You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
Node.js
NPM
Whenever creating a new node project, use to set it up
npm init
NPM is a package manager for node.js and js libraries and frameworks. You can look up packages there, and install them for your project with:
npm install package-name --save
module.exports/require
Traditionally, importing JS files into other JS files has not been supported... until now! There are several ways to do this, but node allows you to add things the to module.exports object.
module.exports = 'foo';
Whatever is on there, will be the return value of
require('yourJSFile.js');
You can assign this to a variable to use later
Instantation
First require express:
var express = require('express'); //include express package
express has lots of abilities, but we just want to start up a server app:
var app = express(); // create an express app
Then make it listen on a port
app.listen(3000, function(){ //start the server
console.log('listening on port ' + PORT);
});