Node Installation
To run Node Server:
node *name of file you want to run in Node*
To install Express, a framework for Node:
$ npm install express --save
To install so that you don’t have to close the terminal every time you edit:
npm install --save-dev nodemon
To install stuff for app.get and app.post for Express:
npm install --save body-parser
To run the server:
run:*start:server OR name of identifier in package.json*
To close terminal:
ctrl+c
Node Short Forms
MEAN: MongoDB Express Angular Node
REST: REpresentational State Transfer
API : Application Program Interface
CORS: Cross-Origin Resource Sharing
Getting started with Node
Node is for communication with the Server-side. Server files always end in .js , and communication is almost always done in the json
format.
Add this to the top to specify that it is a server:
const http = require('http');
After that, add this:
const server = http.createServer((req, res) => { ~Body of server~ });
req is for Request and res is for the Response of the server respectively.
Use this line of code to specify the localhost number you want your server to listen in to:
server.listen(a valid locahost number)
If you change something in your server’s code, you might need to quit the cmd and restart node to see the changes.