Node JS

Setup a NodeJS Project

How to Setup a NodeJS Project from Scratch

9/22/2023
0 views
index.jsJavaScript
const express = require("express");
const config = require("config");

const port = config.get("port");

const app = express();

app.use(express.json());

app.set("view engine", "ejs");
app.use(express.static("views"));


app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).jsonp("Internal Server Error!");
});

app.listen(process.env.PORT || port, async () => {
  console.log(`Server Running at PORT: ${port}`);
});
package.jsonJSON
{
  "name": "auth-form",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Geekboots",
  "license": "ISC",
  "dependencies": {
    "config": "^3.3.9",
    "ejs": "^3.1.9",
    "express": "^4.18.2"
  }
}
Node JSProject SetupNPM init

Loading comments...

Related Examples

Data Validation using Middleware and JOI
Node JS

Data Validation using Middleware and JOI

How to Connect Node.js with MongoDB using Mongoose
Node JS

How to Connect Node.js with MongoDB using Mongoose