37
loading...
This website collects cookies to deliver better user experience
const express = require('express');
const app = express()
app.use(express.static('public'));
app.get('/',function (req,res) {
res.send('ES what?');
})
app.listen(3000, function () {
console.log('App listening on port 3000!')
})
import
over require
:import
helps in selectively loading the pieces of code which are required import
also helps in saving memory loaded onto the apprequire()
's loading is synchronous while import
's loading can be asynchronous; this provides large apps with a performance edge.package.json
file add "type": "module"
to the root of the file as such://package.json
{
"name": "index",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC"
"dependencies": {
"express": "~4.16.1",
}
}
npm i
package
file we have to make the relevant changes to our app's code as follows:import express from 'express';
const app = express();
app.get('/',(req,res) => {
res.send('ES6 is the Node way to go');
})
app.listen(3000,() => {
console.log(`App listening on port 3000!`);
})
@mrinasugosh
) ====