Fri Sep 22 2023

Setup a NodeJS Project

Node JS45 views
Setup a NodeJS Project

File Name: index.js

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}`);
});

File Name: package.json

{
  "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"
  }
}

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.