Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node JS Configuration

I am trying configure my node js to run my html code.I am using bootstrap and Express Js also.When I run node js its not loading the css.Can anyone help me what could be the issue.Here is the node js code snippet.

var express = require("express");
var app     = express();
var path    = require("path");
app.get('/',function(req,res) {
    res.sendFile(__dirname + '/home.html')
})
app.use(express.static(__dirname + '/public'))
app.listen(3000);

console.log("Running at Port 3000");

When I directly load the HTML files it loads the CSS properly but when i use node js to load it it fails.What could be the cause of the issue?

like image 596
Anil Samal Avatar asked Mar 14 '15 10:03

Anil Samal


People also ask

Where is node js configuration file?

The configuration files are located in the default config directory. The location can be overriden with the NODE_CONFIG_DIR environment variable. The NODE_ENV environment variable contains the name of our application's deployment environment; it is development by default.

What is npm configuration?

The npm config command can be used to update and edit the contents of the user and global npmrc files.

What is config js used for?

Config. js allows developers to configure their applications in an XML block instead of hard-coding values inside their scripts or in JSON objects. The XML can be embedded inside an HTML document or in a separate XML file. The configuration block may contain strings, numbers, arrays and HTML.


1 Answers

In express js project to configuration database

/config
  /database.js
/server.js
/.env

const http = require('http');
const app = require('express')();
require('./config/database.js');
const bodyParser = require('body-parser');
const server = http.createServer(app);

server.listen(process.env.ServerPort, '0.0.0.0', () => {
  logger.info(`Express server listening on port ${process.env.ServerPort}`);
});

When you run this:

node server.js

database.js file

const My = require('jm-ez-mysql');

// Init DB Connection
const connection = My.init({
  host: process.env.DBHOST,
  user: process.env.DBUSER,
  password: process.env.DBPASSWORD,
  database: process.env.DATABASE,
  dateStrings: true,
  charset: 'utf8mb4',
  timezone: 'utc',
  multipleStatements: true,
  connectTimeout: 100 * 60 * 1000,
  acquireTimeout: 100 * 60 * 1000,
  timeout: 100 * 60 * 1000,
});

module.exports = {
  connection,
};
like image 149
Mitesh Sathavara Avatar answered Sep 19 '22 18:09

Mitesh Sathavara