You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
to initialise the repository using NPM run, npm init to create the package.json file
complete the following fields in the npm interactive editor : name, version, description, entry point (app.js), git repository (autofill), author
to install run, npm install express --save
then touch app.js
setup Express server in app.js
use express by adding nodes require statement const express = require('express'); (the module is called express and it's the param passed into the parameter function) (the variable express can be used to access the methods and properties of the express module)
call express function and assign it to the app variable const app = express();
set up the development server using the listen method and pass in port number as param app.listen(3000);
start server run node app.js
in browser, type localhost:3000 enter. if there's an error lIke Cannot GET / it's working but need to give express instructions on how to respond to requests - doesnt have any resources to return for this route
Setting up routes
to create a route for the root, use the GET method (used to handle GET requests to a certain URL) on the app object, first param is the location parameter, then as callback add require and request objects . the callback function runs when the client requests the route. The send method is called to send data to the client
app.get('/', (req, res)=> {
res.send('test');
});
app.listen(3000, () => {
console.log('The application is running on localhost:3000!');
});