Tag: node.js

Setup a Node.js development environment is easy but when you need to work in a team, the best option is document all installation steps for everyone.

Every developer must use the same setup or things can be wrong. Bellow are small steps to setup a simple Node.js development environment

1 – Setup Node.js:  https://nodejs.org/en/
2 – Setup VS Code: https://code.visualstudio.com/docs/setup/setup-overview
3 – Open VS Code create a folder and in this folder save an file as app.js
4 – Setup nodemon:
Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development.
To install nodemom open a terminal window and go to the folder you created on step 3 and  type npm install nodemon –save-dev  on the terminal window . This will install nodemon  as development dependency
5 – change package.json to start the application using nodemon
"name": "Node Development",
"version": "1.0.0",
"description": "Just another app",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
},
"author": "Kenio Carvalho",
"license": "ISC",
"devDependencies": {
"nodemon": "^1.18.10"
}
}
5 – Run npm init on the folder and install Express (npm install express –save) //Production dependency

6 Add the code below to app.js and sav, just to test the environment:

const express = require ('express');
const app = express();
app.use('/',(req,res,next)=>{
 
res.send('<h1>Hello from Expres</h1>')
});
app.listen(3000)

7 run npm start on the terminal

open the url localhost:3000 and you will se the page.

Uncategorized